package com.changgou.goods.controller;
import com.changgou.entity.CustomException;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
//springmvc注解 配置全局异常处理类
@ControllerAdvice
public class BaseExceptionHandler {
	//定义捕捉异常类型
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();        
        return new Result(false, StatusCode.ERROR, "执行出错");
    }
    /**
     * 捕获自定义异常
     * @param c
     * @return
     */
    @ExceptionHandler(value = CustomException.class)
    @ResponseBody
    public Result arithmeticException(CustomException c){
        return c.getResult();
    }
}
